#ifndef	SERVER_H
#define	SERVER_H

#include "common.h"

#define	BACKLOG		1024
#define MAX_NR_SFD	500

#define NET_BUF_SIZE	2084
#define NET_IP_LEN	20
#define NET_NAME_LEN	256

typedef struct _SERVER{
	INT32 listen_sfd;
	INT32 nr_client;

	pthread_mutex_t lock;
//	INT32 timeout;
}SERVER;

typedef struct _CLIENT{
	SERVER *server;
	INT32 sfd;
	pthread_t pth;
//	INT32 timeout;
}CLIENT;

typedef struct _NET_ADDR
{
	INT32 servPort;
	INT8  servIp[NET_IP_LEN];
	INT8  servName[NET_NAME_LEN];
}NET_ADDR;

typedef struct _DEV_NET
{
	INT32 rcvSize;
	INT32 sndSize;
	INT8  rcvBuf[NET_BUF_SIZE];
	INT8  sndBuf[NET_BUF_SIZE];
}DEV_NET;

extern SERVER servMa, servSla;
extern DEV_NET s_netMa, s_netSla;
extern NET_ADDR addrMa, addrSla;
extern SOCK_NODE *head;
extern JT808_MSG_PKG Jt808_msgPkg;
extern INT8 bakRcvBuf[NET_BUF_SIZE];
//extern INT8 pBakRcvBuf[NET_BUF_SIZE];

INT32 service_termClient(INT32 sfd);
INT32 service_platfClient(INT32 sfd);
void *service_termThread(void *arg);
void *service_platfThread(void *arg);
INT32 server_new_client(SERVER *s, void *(*pFun)(void *));
INT32 server_init(SERVER *s, NET_ADDR *addr);

#endif /* server.h */
